import matplotlib.pyplot as plt
import numpy as np

n = 12
X = np.arange(n)
Y1 = (1 - X / float(n)) * np.random.uniform(0.5, 1.0, n)
Y2 = (1 - X / float(n)) * np.random.uniform(0.5, 1.0, n)

# 我们可以用 plt.bar 函数中的facecolor参数设置柱状图主体颜色，用edgecolor参数设置边框颜色；而函数 plt.text 可以帮助我们在柱体上方（下方）加上数值：用%.2f保留两位小数，用ha='center'设置横向居中对齐，用va='bottom'设置纵向底部（顶部）对齐
plt.bar(X, +Y1, facecolor='#FFCCCC', edgecolor='white')
plt.bar(X, -Y2, facecolor='#6699CC', edgecolor='white')

for x, y in zip(X, Y1):
    # ha: horizontal alignment
    # va: vertical alignment
    plt.text(x, y, '%.2f' % y, ha='center', va='bottom')

for x, y in zip(X, Y2):
    # ha: horizontal alignment
    # va: vertical alignment
    plt.text(x, -y, '%.2f' % y, ha='center', va='top')

plt.show()
